Fix .netrc parsing
authorFredrik Eriksson <feffe@fulh.ax>
Sat, 28 Dec 2024 11:34:12 +0000 (12:34 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 3 Jan 2025 13:46:33 +0000 (14:46 +0100)
Fixes: #7177
Signed-off-by: Fredrik Eriksson <feffe@fulh.ax>
src/cmd/netrcparser.cpp

index 266fe4f3e29fab84136fbba08268f7f588fe3223..15417e13438830c2c87df82fb749ae2fadbb9c9f 100644 (file)
@@ -14,8 +14,7 @@
 
 #include <QDir>
 #include <QFile>
-#include <QTextStream>
-#include <QStringTokenizer>
+#include <QRegularExpression>
 
 #include <QDebug>
 
@@ -58,32 +57,33 @@ bool NetrcParser::parse()
     }
     QString content = netrc.readAll();
 
-    auto tokenizer = QStringTokenizer{content, u" \n\t"};
+    auto tokens = content.split(QRegularExpression("\\s+"));
 
     LoginPair pair;
     QString machine;
     bool isDefault = false;
-    for(auto itToken = tokenizer.cbegin(); itToken != tokenizer.cend(); ++itToken) {
-        const auto key = *itToken;
+    for(int i=0; i<tokens.count(); i++) {
+        const auto key = tokens[i];
         if (key == defaultKeyword) {
             tryAddEntryAndClear(machine, pair, isDefault);
             isDefault = true;
             continue; // don't read a value
         }
 
-        if (itToken != tokenizer.cend()) {
+        i++;
+        if (i > tokens.count()) {
             qDebug() << "error fetching value for" << key;
             return false;
         }
-        auto value = *(++itToken);
+        auto value = tokens[i];
 
         if (key == machineKeyword) {
             tryAddEntryAndClear(machine, pair, isDefault);
-            machine = value.toString();
+            machine = value;
         } else if (key == loginKeyword) {
-            pair.first = value.toString();
+            pair.first = value;
         } else if (key == passwordKeyword) {
-            pair.second = value.toString();
+            pair.second = value;
         } // ignore unsupported tokens
     }
     tryAddEntryAndClear(machine, pair, isDefault);